import { GetAliasSet } from "./IUtil.js";
import { Character, Icon } from "./ICharacter.js";
import { Text } from "./IText.js";
import { Button } from "./IButton.js";
import { CheckBox, CheckBoxGroup } from "./ICheckBox.js";
import { Radio, RadioGroup } from "./IRadio.js";
import { Input, TextArea } from "./IInput.js";
import { Select, SelectOption } from "./ISelect.js";
import { IImage } from "./IImage.js"

const custom_element_constructors = {};

export function CreateCustomElement(tag) {
    const constructor = custom_element_constructors[tag];
    return constructor ? constructor() : null;
}

export function IsCustomElement(tag) {
    return (typeof custom_element_constructors[tag]) === "function";
}

export function RegisterCustomElement(tag, constructor) {
    const tag_set = GetAliasSet(tag);
    tag_set.forEach((tag) => {
        custom_element_constructors[tag] = constructor;
    });
}

RegisterCustomElement("character", () => new Character());
RegisterCustomElement("icon", () => new Icon());
RegisterCustomElement("text", () => new Text());
RegisterCustomElement("button", () => new Button());
RegisterCustomElement("checkbox", () => new CheckBox());
RegisterCustomElement("checkbox-group", () => new CheckBoxGroup());
RegisterCustomElement("radio", () => new Radio());
RegisterCustomElement("radio-group", () => new RadioGroup());
RegisterCustomElement("input", () => new Input());
RegisterCustomElement("textarea", () => new TextArea());
RegisterCustomElement("select", () => new Select());
RegisterCustomElement("option", () => new SelectOption());
RegisterCustomElement("image", () => new IImage());